<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>虚拟频道列表</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/WdatePicker/skin/WdatePicker.css">
<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"	src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/js/WdatePicker/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" charset="utf-8" src="js/commons.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<%
String f_vc_customid = request.getParameter("f_vc_customid");
if(f_vc_customid==null || "null".equals(f_vc_customid)){
	f_vc_customid = "-1";
}
String f_vc_customName = request.getParameter("f_vc_customName");
String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
	document.onkeydown = function(event) {
		var e = event || window.event || arguments.callee.caller.arguments[0];
		if (e && e.keyCode == 13) { // enter 键
			try {
				searchData();
			} catch (e) {
				gotoSearch($('#easyui-treegrid'));
			}
		}
	};
</script>
<style type="text/css">
.imgsw {
	background: url(../resource/images/a0133.png) no-repeat;
	height: 14px;
	width: 17px;
	display: inline-block;
	border: 0;
}
</style>
<script type="text/javascript">
        var $progamsForm = $('#progamsForm');
		var queryParams;
		var f_vc_parentid=0;
		var f_vc_customid = '<%=f_vc_customid%>';
		var f_vc_customName = '<%=f_vc_customName%>';
		$("#f_vc_customid").val('<%=f_vc_customid%>');
		$("#f_vc_customName").val('<%=f_vc_customName%>');
		function EasyuiDatagrid(){
			$("#easyui-datagrid").datagrid({
				url: '../../virtual_channel/channel_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'id',checkbox:true},
					{field:'f_vc_id',title:'ID',align:'center',width:50},
					{field:'f_vc_name',title:'时段名称',align:'center',width:150},
					{field:'f_vc_airTime',title:'开播时间',align:'center',width:150},
					{field:'f_vc_offAirTime',title:'停播时间 ',align:'center',width:150},
					{field:'f_vcm_materialName',title:'素材名称 ',align:'center',width:250,formatter:function(value,row,index){
						if(value){
							var str =value.split(",");
							var ss="";
							for(var i=0;i<str.length;i++){
								ss+='<span>'+str[i]+'</span><br/>';
							}
							return ss;
						}else {
							return '';
						}
					}},
					{field:'_parentId',title:'操作',align:'center',width:280,
						formatter:function(value,row,index){
							str= '<a id="edit" class="easyui-linkbutton l-btn l-btn-plain" plain="true" iconcls="icon-edit" href="javascript:void(0);" onclick="updatePrograms(\''+row.f_vc_id+'\');"><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a>';
			    			str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-remove" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_vc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a>';
			    			str+= '<a id="info" class="easyui-linkbutton l-btn l-btn-plain" plain="true" iconcls="icon-ok" href="javascript:void(0);" onclick="info(\''+row.f_vc_id+'\');"><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">预览</span></span></a>';
			    			/* <limits:uiAuth url="review_content.do"> */	
				    		if(row.f_vc_status==2 || row.f_vc_status==4) {//待审核
				    			str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickupdateStatus(\''+row.f_vc_id+'\',1);" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">审核</span></span></a>';
				    		}
				    		if(row.f_vc_status==1 || row.f_vc_status==6) {//审核通过待投放
				    			str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickupdateStatus(\''+row.f_vc_id+'\',5);" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">投放</span></span></a>';
				    		}
				    		if(row.f_vc_status==5){//取消投放
				    			str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickupdateStatus(\''+row.f_vc_id+'\',6);" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">取消投放</span></span></a>';
				    		}
				    		/* </limits:uiAuth> */
			    			return str;
				    	}
					}
				]],
				singleSelect:true,
				pagination: true,
				pageList:[10000],
				pageSize:10000,
				toolbar: '#toolbar',
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function (data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
							if (r){
							    window.parent.location.href='/cbweb';
							    return false;
							}
						});
					}else if(data.total >0){
						f_vc_parentid=data.rows[0].f_vc_parentid;
					}else{
						f_vc_parentid=0;
					}
				}
			});
	    }
		function getGueryParams(){
			return {
				f_vc_customid:$("#f_vc_customid").val(),
				f_vc_type:1//,//类型，1，正常编辑节目 2，插播节目
				//f_vc_status:1//'状态，1：代表有效，2：代表无效，3：代表伪删除，4：审核不通过 5:正在投放  ',
				//f_vc_putInDate:$("#f_vc_putInDate").val()
			};
		}
		
		function init(){
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			f_vc_customid = $("#f_vc_customid").val();
			getSeverTime('servertime');
			
			onClickBtnDelete = function(id){
				$.messager.confirm('确定删除内容','确定删除内容么?',function(r){
					if(r){
						app_ajax('../../virtual_channel/delete_channel.do?f_vc_id='+id+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
						'',
						function(msg){
							if(msg.success) {
								alert("删除成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
							} else {
								alert("删除异常，请联系管理员");
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
							window.location.reload();
						}
						);
					}
				});
			};
			
			
			onClickupdateStatus = function(id,_type){//修改数据状态
				var notestr = '';
				var notetitle = '';
				switch(_type){
					case 1:
						notetitle = '确定节目单审核';
						notestr = '确定要审核通过该内容吗?';
						break;
					case 5:
						notetitle = '确定节目单投放';
						notestr = '确定要投放该节目单吗?';
						break;
					case 6:
						notetitle = '确定取消节目投放';
						notestr = '确定要取消投放该节目单吗?';
						break;
				}
				$.messager.confirm(notetitle,notestr,function(r){
					if(r){
						app_ajax('../../virtual_channel/update_vchannel_status.do?f_vc_id='+id+'&f_vc_status='+_type+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
						'',
						function(msg){
							if(msg.success) {
								alert("操作成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
							} else {
								alert("操作异常，请联系管理员");
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
						}
						);
					}
				});
			};//修改数据状态===end
		}
		$(function(){
			init();
		});
		
		function info(id){
			window.location.href = 'vchannel_programs_material_list.jsp?f_vc_id='+id;
		}
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
			 $(".datebox :text").attr("readonly","readonly");
		}
		function onpress(){
		var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
   		  	if (event.keyCode == 13){  
      			gotoSearch($('#easyui-treegrid'));
    		}
		}
		
		//$(function(){
		//	console.log('节目列表页,如果已有编辑好的节目单,把节目单对应的父id传到新增页->f_vc_parentid:'+f_vc_parentid+';f_vc_customid:'+f_vc_customid);
/* 			$('#addPrograms').on('click',function(){
				var action = "vchannel_program_edit.jsp?insertOrUpdate=insert&f_vc_parentid="+f_vc_parentid+"&f_vc_customid="+f_vc_customid;
				window.location.href = action;
	   			return false;
			}); */
		//});
		/* 
			节目编制  新增
		*/
		function addPrograms() {
			if($("#f_vc_customid").val() == -1){
				$.messager.confirm('选择客户提醒','请先选择客户!');
				return false;
			}
			document.forms[0].action = "vchannel_program_edit.jsp?insertOrUpdate=insert&f_vc_parentid="+f_vc_parentid+"&f_vc_customid="+$("#f_vc_customid").val();
			document.forms[0].submit();
		}
		/* 
			节目编制   修改
		*/
		function updatePrograms(f_vc_id) {
			document.forms[0].action = "vchannel_program_edit.jsp?insertOrUpdate=update&f_vc_id="+f_vc_id+"&f_vc_parentid="+f_vc_parentid+"&f_vc_customid="+$("#f_vc_customid").val();
			document.forms[0].submit();
		}
		/*  插播删除 */
		function review(id){
			$.messager.confirm('确定删除内容','确定删除内容么?',function(r){
				if(r){
					app_ajax('../../virtual_channel/delete_channel.do?f_vc_id='+id+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
					'',
					function(msg){
						if(msg.success) {
							alert("删除成功!");
							if (checkAjaxRequestValidity(msg)) {
								gotoSearch($('#easyui-treegrid'));
							}
						} else {
							alert("删除异常，请联系管理员");
							if($.isFunction(window.showMessager)){
								window.showMessager(msg.resultTitle,msg.result);
							}
						}
						window.location.reload();
					}
					);
				}
			});
		}
		/* 模板列表页 */
		function modelManage() {
			if($("#f_vc_customid").val() == -1){
				$.messager.confirm('选择客户提醒','请先选择客户!');
				return false;
			}
			document.forms[0].action = "vchannel_program_template_list.jsp?preform=select&f_vc_customid="+$("#f_vc_customid").val();
			document.forms[0].submit();
		}
		function selectCustomer(){
			openDialog($('#org_list'),'../behavior_control/org_update.jsp?idField=f_vc_customid&nameField=f_vc_customName');
		}
		function resert(){
			$("#f_vc_customName").val("");
			$("#f_vc_customid").val("-1");
		}
		
		function effectData(){
			if(f_vc_parentid == 0){
				$.messager.confirm('暂无可操作内容','请先去编制节目!');
				return false;
			}
			$.messager.confirm('确定即时生效','确定要生效么?',function(r){
				if(r){
					app_ajax('../../virtual_channel/update_effect_status.do?f_vc_parentid='+f_vc_parentid+'&f_vc_customid='+$("#f_vc_customid").val()+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
					'',
					function(msg){
						if(msg.success) {
							alert("操作成功!");
							if (checkAjaxRequestValidity(msg)) {
								gotoSearch($('#easyui-treegrid'));
							}
						} else {
							alert("操作异常，请联系管理员");
							if($.isFunction(window.showMessager)){
								window.showMessager(msg.resultTitle,msg.result);
							}
						}
						window.location.reload();
					}
					);
				}
			});
		}
	</script>
  </head>
  <body onload="load();">
	<table id="easyui-datagrid" title="节目列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
	
		<div class="easyuiSearch">
			<form onsubmit="return false;" id="progamsForm" action="" method="post">
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="right" width="8%">行业客户：</td>
						<td align="left" width="35%">
							<input name="f_vc_customid" id="f_vc_customid" value="-1" style="width: 140px;"  onChange="init();" type='hidden' />
						    <input name="f_vc_customName" id="f_vc_customName" style="width: 140px;" onkeydown="onpress();" />
						    <a id="12" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);" onclick="resert()">空选</a>
							<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="selectCustomer()">请选择</a> 
						</td>
						<td align="right" width="10%">播出日期：</td>
						<td align="left" width="2%">
							<input id="f_vc_putInDate" name="f_vc_putInDate" type="text" onClick="WdatePicker()" onkeydown="onpress();" style="width: 100px;"  value="" class="yl_inp yw_name" />	
						</td>
						<td id="servertime" style="text-align: right; " ></td><!-- font-weight: bold -->
					</tr>
					<tr>
					    <td colspan="4" align="right">
					        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search', plain:true" onclick="init()">搜索</a>
					        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" onclick="effectData();">即时生效</a> 
						</td>
						<td colspan="4" align="center">
<!-- 							<button id="addPrograms" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:true">节目编制</button>
 -->						    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:true" onclick="addPrograms()">节目编制</a> 
							<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:true" onclick="modelManage()">模板</a>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>


	<div id="dlg" class="easyui-dialog" style="width: 900px; height: 700px; padding-top: 0px;"
		data-options="title: '工单详情', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0" style="width: 100%; height: 99%;"></iframe>
	</div>
	<div id="org_list" class="easyui-dialog" style="width:750px;height:530px;padding-top: 0px;"
	    data-options="title: '行业客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#openselect_buttons'">
	   	<iframe scrolling="auto" frameborder="0" style="width:100%;height:99%;"></iframe>
   </div>
	</body>

</html>